import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets
// 抹平不同浏览器差异  line-height   1：安装：  npm i normalize.css  2:导入

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
// 导航守卫
import '@/permission' // permission control
/*
全局自定义指令
Vue.directive(指令名,{生命周期})
*/
// Vue.directive('imgError', {
//   inserted(dom, obj) {
//     dom.src = dom.src || obj.value
//     dom.onerror = function() {
//       dom.src = obj.value
//     }
//   },
//   componentUpdated(dom, obj) {
//     dom.src = dom.src || obj.value
//   },
//   unbind(dom) {
//     dom.onerror = null
//   }
// })
import directivesJs from '@/directives'
import HmNum from '@/components/lib/hmNum.vue'
// 使用vue.use全局注册
import libJs from '@/components/lib/index.js'
import filters from '@/filters/index.js'
// 导入打印插件
import i18n from '@/lang'
import Print from 'vue-print-nb'
// import mixinjs from '@/mixin'
// Vue.mixin(mixinjs)
Vue.use(Print)
Vue.use(libJs, '我是全局注册')
// import PageTools from '@/components/lib/pageTools.vue'
Vue.component(HmNum.name, HmNum)
// Vue.component(PageTools.name, PageTools)
Vue.prototype.$bus = new Vue()
// for (const key in directivesJs) {
//   Vue.directive(key, directivesJs[key])
// }
// Object.keys({a:1,b:2})===>[a,b]
// Object.values({a:1,b:2})===>[1,2]
// Object.entries({a:1,b:2})===>[[a,1],[b,2]]
Object.keys(directivesJs).forEach((item) => {
  Vue.directive(item, directivesJs[item])
})
Object.keys(filters).forEach((item) => {
  Vue.filter(item, filters[item])
})

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// process.env.NODE_ENV===development/production
// 如果当前环境是生产环境继续使用mock
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value)
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: (h) => h(App) // createElement:创建虚拟dom
})
